import { createRouter, createWebHashHistory } from 'vue-router'

// 导入视图组件
// 使用懒加载方式导入组件，提高性能
const Dashboard = () => import('../views/Dashboard.vue')
const ProjectManagement = () => import('../views/ProjectManagement.vue')
const ProjectDetail = () => import('../views/ProjectDetail.vue')
const ProjectCreate = () => import('../views/ProjectCreate.vue')
const ProjectEdit = () => import('../views/ProjectEdit.vue')
const MilestoneDetail = () => import('../views/MilestoneDetail.vue')
const ProgressUpdate = () => import('../views/ProgressUpdate.vue')
const DataExport = () => import('../views/DataExport.vue')
// const ReportGeneration = () => import('../views/ReportGeneration.vue')
const SystemSettings = () => import('../views/SystemSettings.vue')

// 定义路由
const routes = [
  {
    path: '/',
    redirect: '/dashboard'
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: Dashboard,
    meta: { title: '仪表盘（数据大屏）' }
  },
  {
    path: '/projects',
    name: 'ProjectManagement',
    component: ProjectManagement,
    meta: { title: '项目管理' }
  },
  {
    path: '/project-detail/:id',
    name: 'ProjectDetail',
    component: ProjectDetail,
    props: true,
    meta: { title: '项目详情' }
  },
  {
    path: '/project-create',
    name: 'ProjectCreate',
    component: ProjectCreate,
    meta: { title: '新建项目' }
  },
  {
    path: '/project-edit/:id',
    name: 'ProjectEdit',
    component: ProjectEdit,
    props: true,
    meta: { title: '编辑项目' }
  },
  {
    path: '/milestone-detail/:id',
    name: 'MilestoneDetail',
    component: MilestoneDetail,
    props: true,
    meta: { title: '工程节点详情' }
  },
  {
    path: '/progress-update',
    name: 'ProgressUpdate',
    component: ProgressUpdate,
    meta: { title: '进度更新' }
  },
  {
    path: '/data-export',
    name: 'DataExport',
    component: DataExport,
    meta: { title: '数据导出' }
  },
  // {
  //   path: '/report-generation',
  //   name: 'ReportGeneration',
  //   component: ReportGeneration,
  //   meta: { title: '报告生成' }
  // },
  {
    path: '/system-settings',
    name: 'SystemSettings',
    component: SystemSettings,
    meta: { title: '系统设置' }
  }
]

// 创建路由实例
const router = createRouter({
  // 使用hash模式，确保在Electron中正常工作
  history: createWebHashHistory(),
  routes
})

// 路由前置守卫，用于设置页面标题
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `军队工程管理系统 - ${to.meta.title}`
  }
  next()
})

export default router 